package com.springBoot;

import java.util.Date;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.springBoot.dao.UserDao;
import com.springBoot.druid.DruidConfig;

@Controller
public class ControllerTest {

	@Autowired
	private Environment env;

	@Resource
	UserDao userDao;

	@Value("${username}")
	private String username;
	
	@Resource
	DruidConfig druidConfig;
	
//	@Resource
//	StringRedisTemplate stringRedisTemplate;

	@RequestMapping("/hello001")
	@ResponseBody
	public String hello001() {
		return "123";
	}

	@RequestMapping("/hello")
	public String hello(Model model) {
		System.out.println(username);
		System.out.println(druidConfig.getDbUrl());
//		stringRedisTemplate.opsForValue().set("1", "3");
//		System.out.println(stringRedisTemplate.opsForValue().get("1"));
		model.addAttribute("userName", userDao.selectAll().get(0).get("auditingCode"));
		return "hello";
	}
	
	@RequestMapping("/toLogin")
	public String toLogin(Model model,String userName,HttpServletRequest request) {
		request.setAttribute("name", "ddd");
		request.setAttribute("today", new Date());
		request.setAttribute("flag", true);
		request.getSession().setAttribute("sessionName", "哈哈哈哈哈哈");
		return "login";
	}
	
	@RequestMapping("/login")
	public String login(Model model,String userName,HttpServletRequest request) {
//		model.addAttribute("userName", userDao.selectAll().get(0).get("auditingCode"));
		request.getSession().setAttribute("userName", userName);
		return "hello";
	}
}
